package com.google.project.server.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.jdo.annotations.Element;
import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.project.shared.DailyReportDTO;

@SuppressWarnings("serial")
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class DailyReport implements Serializable{
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
	private String id;
	@Persistent
	private Project project;
	@Persistent
	private Long createdOnDate;
	@Persistent
	private Long updateTime;
	@Persistent
	private Long reportForDate;
	@Persistent
	private String fromUserID;
	@Persistent
	private String fromUserName;
	@Persistent
	private int status;
	@Persistent
	private String projectId;
	
	@Persistent(mappedBy = "dailyReport")
	@Element(dependent = "true")
	private List<DailyReportDetail> listOfReportDetail = new ArrayList<DailyReportDetail>();
	
	public DailyReport() {
	}

	public DailyReport(String id,Long createdOnDate, Long updateTime,Long reportForDate, String fromUserID,
			String fromUserName, int status) {
		super();
		this.id = id;
		this.createdOnDate = createdOnDate;
		this.updateTime = updateTime;
		this.reportForDate=reportForDate;
		this.fromUserID = fromUserID;
		this.fromUserName = fromUserName;
		this.status = status;
	}
	public DailyReport(DailyReportDTO dailyReportDTO) {
		this.projectId=dailyReportDTO.getProjectID();
		this.createdOnDate = dailyReportDTO.getCreatedOnDate();
		this.updateTime = dailyReportDTO.getUpdateTime();
		this.reportForDate=dailyReportDTO.getReportForDate();
		this.fromUserID = dailyReportDTO.getFromUserID();
		this.fromUserName = dailyReportDTO.getFromUserName();
		this.status = dailyReportDTO.getStatus();
	}

	public DailyReportDTO toDTO() {
		DailyReportDTO data = new DailyReportDTO();
		data.setId(id);
		data.setCreatedOnDate(createdOnDate);
		data.setUpdateTime(updateTime);
		data.setReportForDate(reportForDate);
		data.setFromUserID(fromUserID);
		data.setFromUserName(fromUserName);
		data.setStatus(status);
		data.setProjectID(projectId);
		data.setProjectDTO(this.project.toDTO());
		data.setNumOfTask(this.getListOfReportDetail().size());
		return data;
	}
	public void updateFromDTO(DailyReportDTO dailyReportDTO) {
		this.projectId=dailyReportDTO.getProjectID();
		this.createdOnDate = dailyReportDTO.getCreatedOnDate();
		this.updateTime = dailyReportDTO.getUpdateTime();
		this.reportForDate=dailyReportDTO.getReportForDate();
		this.fromUserID = dailyReportDTO.getFromUserID();
		this.fromUserName = dailyReportDTO.getFromUserName();
		this.status = dailyReportDTO.getStatus();
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public Project getProject() {
		return project;
	}
	public void setProject(Project project) {
		this.project = project;
	}
 
	public Long getCreatedOnDate() {
		return createdOnDate;
	}
	public void setCreatedOnDate(Long createdOnDate) {
		this.createdOnDate = createdOnDate;
	}
	public Long getUpdateTime() {
		return updateTime;
	}
	public void setUpdateTime(Long updateTime) {
		this.updateTime = updateTime;
	}
	public String getFromUserID() {
		return fromUserID;
	}
	public void setFromUserID(String fromUserID) {
		this.fromUserID = fromUserID;
	}
	public String getFromUserName() {
		return fromUserName;
	}
	public void setFromUserName(String fromUserName) {
		this.fromUserName = fromUserName;
	}
	public int getStatus() {
		return status;
	}
	public void setStatus(int status) {
		this.status = status;
	}

	public List<DailyReportDetail> getListOfReportDetail() {
		return listOfReportDetail;
	}

	public void setListOfReportDetail(List<DailyReportDetail> listOfReportDetail) {
		this.listOfReportDetail = listOfReportDetail;
	}

	public Long getReportForDate() {
		return reportForDate;
	}
	
	public void setReportForDate(Long reportForDate) {
		this.reportForDate = reportForDate;
	}

	public String getProjectId() {
		return projectId;
	}

	public void setProjectId(String projectId) {
		this.projectId = projectId;
	}	
	
}
